home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 291_01 / jjbkbd.h < prev    next >
Text File  |  1989-06-26  |  9KB  |  151 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  *                               jjbkbd.h                                   *
  4.  *                                                                          *
  5.  *   Copyright (c) 1988, 1989, JJB. All rights reserved.                    *
  6.  *                                                                          *
  7.  *   Purpose:                                                               *
  8.  *                                                                          *
  9.  *      The purpose of this file is to make definitions for the keyboard    *
  10.  *      and to explain to you how important the get_ch() function is        *
  11.  *      and why it is considered to be at the heart of the entire JJB       *
  12.  *      programming environment.                                            *
  13.  *                                                                          *
  14.  *                                                                          *
  15.  *     JJB, 9236 Church Rd suite 1082, Dallas, Tx 75231 (214) 341-1635      *
  16.  ****************************************************************************/
  17.  
  18. #ifndef BL
  19. #define BL   32
  20. #define RET  '\015'
  21. #define AST  '\052'
  22. #define ESC  '\033'
  23. #define BSPC '\010'
  24.  
  25. /****************************************************************************
  26.  *                                                                          *
  27.  *           get_ch()      get_num()     get_any();                         *
  28.  *                                                                          *
  29.  *  If you have the printed documentation of JJB, you can see how there are *
  30.  *  There are 5 low level functions you can use below the function get_ch() *
  31.  *  and 3 higher level functions above it which give you absolute control   *
  32.  *  over the keyboard.                                                      *
  33.  *                                                                          *
  34.  *      char get_ch();   the equivalent of 'getch()'                        *
  35.  *      char get_num();  read numeric                                       *
  36.  *      char get_any();  wait for any key to be pressed                     *
  37.  *                                                                          *
  38.  ****************************************************************************/
  39.  
  40. #define SPACEBAR_PRESSED    (get(IKEY) == 32)
  41. #define ESC_PRESSED         (getc(KEY) == ESC)
  42. #define F1_PRESSED          (!get(IKEY) && get(IK_EXT) == 59)
  43. #define ALT_PRESSED         (get(IK_CODE) & 8)
  44. #define RETURN_PRESSED      (getc(KEY) == RET)
  45. #define REMOVE_PRESSED      (getc(KEY) == getc(REMOVE) )
  46. #define BSPC_PRESSED        (getc(KEY) == BSPC)
  47. #define LEFTSHIFT_PRESSED   (get(IK_CODE) & 1)
  48. #define RIGHTSHIFT_PRESSED  (get(IK_CODE) & 2)
  49. #define SHIFT_PRESSED       (get(IK_CODE) & 3)
  50. #define CTRL_PRESSED        (get(IK_CODE) & 4)
  51. #define SCROLLLOCK_ACTIVE   (get(IK_CODE) & 16)
  52. #define NUMLOCK_ACTIVE      (get(IK_CODE) & 32)
  53. #define CAPS_ACTIVE         (get(IK_CODE) & 64)
  54. #define INSERT_ACTIVE       (get(IK_CODE) & 128)
  55.  
  56. #define LEFTARROW_PRESSED   (!get(IKEY) &&  get(IK_EXT) == 75)
  57. #define RIGHTARROW_PRESSED  (!get(IKEY) &&  get(IK_EXT) == 77)
  58. #define UPARROW_PRESSED     (!get(IKEY) &&  get(IK_EXT) == 72)
  59. #define DOWNARROW_PRESSED   (!get(IKEY) &&  get(IK_EXT) == 80)
  60.  
  61. #define PGUP_PRESSED        (!get(IKEY) &&  get(IK_EXT) == 73)
  62. #define PGDN_PRESSED        (!get(IKEY) &&  get(IK_EXT) == 81)
  63. #define HOME_PRESSED        (!get(IKEY) &&  get(IK_EXT) == 71)
  64. #define END_PRESSED         (!get(IKEY) &&  get(IK_EXT) == 79)
  65. #define CTRLG_PRESSED       (get(IKEY) == 7)
  66. #define FUNCT_PRESSED       (!get(IKEY)  && between(get(IK_EXT),59,72))
  67.  
  68.  
  69. /****************************************************************************
  70.  *                                                                          *
  71.  *                            keyboard                                      *
  72.  *                                                                          *
  73.  *   Most C programmers are used to 'ch = getch();'                         *
  74.  *                                                                          *
  75.  *   In JJB, just use:    'get_ch();'                                       *
  76.  *                        'get_num();'                                      *
  77.  *                        'get_any();'                                      *
  78.  *                                                                          *
  79.  *   You can still 'ch = get_ch()', however JJB operates at such a high-    *
  80.  *   level of programming that it is not necessary.                         *
  81.  *                                                                          *
  82.  ****************************************************************************/
  83.  
  84.  
  85.  
  86. /****************************************************************************
  87.  *                                                                          *
  88.  *                              get_ch()                                    *
  89.  *                                                                          *
  90.  *   Use get_ch() instead of getch().                                       *
  91.  *   The reason you must use get_ch() is because JJB needs to look at every *
  92.  *   keypress to see if ALT has been pressed for changing options.          *
  93.  *                                                                          *
  94.  *   also, JJB is designed to execute get_ch() without expecting            *
  95.  *   a return value. Everytime you use get_ch(), JJB does a BIOS            *
  96.  *   read, updating four characters: KEY, KEYU, K_EXT & K_CODE and four     *
  97.  *   integers: IKEY, IKEYU, IK_EXT, and IK_CODE.  These values are          *
  98.  *   stored in arrays and are accessible from any object module             *
  99.  *   with the 'get(' and 'set(' functions described in  'JJBSET.H'.         *
  100.  *                                                                          *
  101.  *   Here is an example:                                                    *
  102.  *                                                                          *
  103.  *            get_ch();                                                     *
  104.  *                                                                          *
  105.  *            if (ESC_PRESSED) do_something();                              *
  106.  *                                                                          *
  107.  *                                                                          *
  108.  *   Everytime you use get_ch(), JJB sets in arrays:                        *
  109.  *                                                                          *
  110.  *     K_AL_REG  to low byte  reg.h.al in keyboard interrupt kbint()        *
  111.  *     K_AH_REG  to high byte reg.h.ah in keyboard interrupt kbint()        *
  112.  *     K_IAL_REG to integer of K_AL_REG                                     *
  113.  *     K_IAH_REG to integer of K_AH_REG                                     *
  114.  *                                                                          *
  115.  *     KEY       to the character of the key you pressed.                   *
  116.  *     KEYU      to KEY taken to upper case.                                *
  117.  *     IKEY      to integer of KEY. If 'a' pressed, IKEY would be 97.       *
  118.  *     IKEYU     to integer of KEYU. If 'a' pressed, IKEYU would be 65      *
  119.  *     K_EXT     if KEY = '\0', K_EXT holds the value of the special key.   *
  120.  *     IK_EXT    to the integer value of K_EXT.                             *
  121.  *     K_CODE    to the keyboard scan code.                                 *
  122.  *     IK_CODE   to the keyboard scan code taken to an integer value.       *
  123.  *                                                                          *
  124.  *   You may still use 'ch = get_ch()', but it is no longer necessary       *
  125.  *   because JJB handles everything for you. The JJB input and enter        *
  126.  *   functions are designed to be high